<%@page import="com.google.appengine.api.datastore.Entity"%>
<%@page import="com.google.appengine.api.datastore.KeyFactory"%>
<%@page import="com.google.appengine.api.datastore.Key"%>
<%@page import="sistem.manangement.model.*"%>
<%@page
	import="com.google.appengine.api.datastore.DatastoreServiceFactory"%>
<%@page import="com.google.appengine.api.datastore.DatastoreService"%>
<%@page import="com.google.appengine.api.users.*"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<%@include file="/includes/user-services.jsp"%>
	<div>
		<%
			if (mUser != null) {
		%>
		<div>
			Hello
			<%=mUser.getNickname()%>
			<%
				Key userKey = KeyFactory.createKey("user", mUser.getEmail());
					Entity userEntity;
					try {
						userEntity = datastore.get(userKey);
						mSmuser.setEmail((String) userEntity.getProperty("email"));
						if (((String) userEntity.getProperty("usertype")).equals(UserType.ADMINISRTATOR.toString())) {
							response.sendRedirect("/html/administrator.jsp");
						}

					} catch (Exception e) {
						e.printStackTrace();
						System.out.println("Nu exista utilizatorul, va fi creat");
						userEntity = new Entity(userKey);
						userEntity.setProperty("email", mUser.getEmail());
						userEntity.setProperty("name", "No name");
						userEntity.setProperty("usertype", UserType.PACIENT.toString());
						datastore.put(userEntity);
					}
			%>
			<a href="<%=mUserService.createLogoutURL(request.getRequestURI())%>">Log
				out</a>
		</div>
		<%
			} else {
		%>
		<div>
			Please sign in <a
				href="<%=mUserService.createLoginURL(request.getRequestURI())%>">Log
				in</a>
		</div>
		<%
			}
		%>
	</div>

</body>
</html>